package ru.gerunn.clarg;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

public class CLArg {

	private ArrayList<String> arrayList = new ArrayList<String>();
	private Map<String, ArrayList<String>> map = new HashMap<String, ArrayList<String>>();

	public void add(String string) {
		this.arrayList.add(string);
	}

	public void add(String name, String value) {
		ArrayList<String> vArrayList = this.map.get(name);

		if (vArrayList == null) {
			vArrayList = new ArrayList<String>();
			this.map.put(name, vArrayList);
		}

		vArrayList.add(value);
	}
	
	public void enable(String name) {
		this.map.put(name, new ArrayList<String>());
	}

	public String get(Integer key) {
		if (this.arrayList.size() > key && key > -1) {
			return this.arrayList.get(key);
		} else {
			return null;
		}
	}

	public ArrayList<String> get(String name) {
		return this.map.get(name);
	}
	
	public String get(String name, Integer key) {
		ArrayList<String> vArrayList = this.map.get(name);
		if (vArrayList == null) {
			return null;
		} else {
			if (vArrayList.size() > key && key > -1) {
				return vArrayList.get(key);
			} else {
				return null;
			}
		}
	}
	
	public String getCL() {
		//String ret = "";
		ArrayList<String> al = new ArrayList<String>();
		for (String k : this.arrayList) {
			al.add(k);
			//ret = ret + k + " ";
		}
		
		for (String k : this.map.keySet()) {
			al.add(k);
			//ret = ret + k + " ";
			for (String kk : this.map.get(k)) {
				al.add(kk);
				//ret = ret + kk + " ";
			}
		}
		return al.toString();
		//return ret;
	}
}
